package com.yvon.maple.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import org.apache.commons.lang3.StringUtils;


public enum MessageCategory {

    /**
     * 站内.
     */
    station("station", "站内"),

    /**
     * 短信.
     */
    sms("sms", "短信"),


    /*
     * 电子邮件.
     */
    email("email", "电子邮件");


    /**
     * Code
     */
    @EnumValue
    private final String code;

    /**
     * Name
     */
    private final String message;


    /**
     * Message category.
     *
     * @param code the code
     * @param name the name
     */
    MessageCategory(String code, String name) {
        this.code = code;
        this.message = name;
    }

    /**
     * Get code string.
     *
     * @return {@link String }
     * @author : Yvon / 2021-08-26
     */
    @JsonValue
    public String getCode() {
        return code;
    }

    /**
     * Get message string.
     *
     * @return {@link String }
     * @author : Yvon / 2021-08-26
     */
    public String getMessage() {
        return message;
    }

    @Override
    public String toString() {
        return code + ":" + message;
    }

    public static MessageCategory getByCode(String code){
        for (MessageCategory p : MessageCategory.values()) {
            if (StringUtils.equals(code, p.getCode())){
                return p;
            }
        }
        return null;
    }
}